import http from "@/http";

export const userListApi = (params: IUserListParams): RES<IUserListModel> =>
  http.get("/admin/list", { params });

export const switchUserStatusApi = (id: number, status: number): RES<number> =>
  http.post(`/admin/updateStatus/${id}?status=${status}`);

export const addUserApi = (params: IUserModel): RES<IUserModel> =>
  http.post("/admin/register", params);

export const getUserById = (id: number): RES<IUserModel> =>
  http.get(`/admin/${id}`);

export const updateUser = (params: IUserModel): RES<number> =>
  http.post(`/admin/update/${params.id}`, params);

export const getRoleListApi = (): RES<IRoleModel[]> =>
  http.get("/role/listAll");

export const getRolesByUserIdApi = (adminId: number): RES<IRoleModel[]> =>
  http.get(`/admin/role/${adminId}`);

export const updateUserRolesApi = (id: number, ids: number[]): RES<number> =>
  http.post(`/admin/role/update?adminId=${id}&roleIds=${ids.join(",")}`);

export const userRoleListApi = (
  keyword: string,
  pageNum?: number,
  pageSize?: number
): RES<RootObjectTow> =>
  http.get(
    `/role/list?keyword=${keyword}&pageNum=${pageNum}&pageSize=${pageSize}`
  );
export const roleUserStatusApi = (id: number, status: number): RES<number> =>
  http.post(`/role/updateStatus/${id}?status=${status}`);

export const createUser = (params: IRoleModelTwo): RES<number> =>
  http.post(`/role/create`, params);

export const roleupDataUser = (
  id: number,
  params: IRoleModelTwo
): RES<number> => http.post(`/role/update/${id}`, params);

export const getRourceListByRoleIdApi = (
  roleId: number
): RES<IResourceModel[]> => http.get(`/role/listResource/${roleId}`);
export const resourceListAllApi = (): RES<IResourceModel[]> =>
  http.get("/resource/listAll");
export const resourceCategoryListAllApi = (): RES<IResourceCategoryModel[]> =>
  http.get("/resourceCategory/listAll");
export const allocResourceApi = (
  paramas: allocResourcePramas
): RES<allocResource[]> =>
  http.post(
    `/role/allocResource?roleId=${
      paramas.roleId
    }&resourceIds=${paramas.resourceIds.join(",")}`
  );

  export const getTreeListAPI=():RES<ITreeModel[]>=>http.get('/menu/treeList')

  export const getMenuByIdAPI=(roleId:number):RES<IMenuModel[]>=>http.get(`/role/listMenu/${roleId}`)
  
  export const allocMenuAPI=(params:allocResourceParams)=>http.post(`/role/allocMenu?menuIds=${params.resourceIds.join(',')}&roleId=${params.roleId}`)